package com.xyz.tasks.tdo;

import com.free.ext.logger.FreeLogger;
import com.free.ext.logger.FreeLoggerFactory;
import com.free.ext.quartz.TaskContainer;
import com.free.ext.quartz.model.TaskRes;
import com.free.ext.quartz.tasker.RemoteUrlTasker;
import com.xyz.domain.constants.ConstantsLotteryTaskFormater;
import com.xyz.domain.table.SLottery;

public class StartTasker extends RemoteUrlTasker {

    private static final FreeLogger LOG = FreeLoggerFactory.getLogger(StartTasker.class);

    @Override
    public TaskRes execute() {
        if(!this.getParams().containsKey(ConstantsLotteryTaskFormater.LOTTERY_TASK_PARAM_OBJ)){
            return TaskRes.error(null);
        }
        LOG.info("开始进程被唤醒了,");
        SLottery lotteryInfo = (SLottery)this.getParams().get(ConstantsLotteryTaskFormater.LOTTERY_TASK_PARAM_OBJ);
        LOG.info("开始进程 操作今天的信息{},",lotteryInfo.getCode());
        String procCode = String.format(ConstantsLotteryTaskFormater.LOTTERY_TASK_CODE_PROC, lotteryInfo.getCode());
        int seconds = TaskerDealUtils.getFixedSpanSeconds(lotteryInfo);
        int tmpSeconds = seconds - ConstantsLotteryTaskFormater.LOTTERY_TASK_CACULATE_SECONDS;
        LOG.info("开始进程 唤醒今天的任务{},",lotteryInfo.getCode());
        TaskerDealUtils.executeAndResumeTaskAfterSeconds(tmpSeconds, ConstantsLotteryTaskFormater.LOTTERY_TASK_GROUP, procCode);
        return null;
    }
}
